package pers.kw.server.controller;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import pers.kw.protocol.R;
import pers.kw.server.dto.OrderReqDto;
import pers.kw.server.service.OrderService;
import pers.kw.validate.ModifyGroup;

import javax.annotation.Resource;
import javax.validation.Valid;
import javax.validation.groups.Default;

@Api(tags = "订单服务")
@RequestMapping(value = "/order/api/")
@RestController
public class OrderController {

    @Resource
    private OrderService orderService;

    @ApiOperation(value = "创建订单")
    @PostMapping(value = "create/order")
    public R<String> createOrder(@Valid @RequestBody OrderReqDto reqDto) {
        return R.ok(orderService.createOrder(reqDto));
    }


    @ApiOperation(value = "修改订单")
    @PostMapping(value = "update/order")
    public R updateOrder(@Validated(value = {Default.class, ModifyGroup.class})
                         @RequestBody OrderReqDto reqDto) {
        orderService.updateOrder(reqDto);
        return R.ok();
    }
}
